Imports System
Imports NUnit.Framework
Imports ValidationFramework
Imports ValidationFramework.Reflection

Public Class AddWithTypeCacheExample

#Region "Example"
    Public Class Person
        Private _age As Integer
        Private _validationManager As MemberValidationManager

        Public Sub New()
            _validationManager = ValidationManagerFactory.GetPropertyValidationManager(Me)
        End Sub



        Public Function Validate() As Boolean
            _validationManager.Validate("Age")
            Return _validationManager.IsValid
        End Function


        ' Properties
        Public Property Age() As Integer
            Get
                Return _age
            End Get
            Set(ByVal value As Integer)
                _age = value
            End Set
        End Property


    End Class

    <TestFixture()> _
    Public Class ExampleUsage

        <Test()> _
        Public Sub Run()
            Dim personType As Type = GetType(Person)
            Dim propertyDescriptor As PropertyDescriptor = _
            TypeCache.GetType(personType.TypeHandle).GetOrCreatePropertyDescriptor("Age")
            Dim rule As New RequiredRule(Of Integer)()
            propertyDescriptor.Rules.Add(rule)
            Dim _person As New Person
            Assert.IsFalse(_person.Validate)
            _person.Age = 10
            Assert.IsTrue(_person.Validate)
        End Sub

    End Class
#End Region
End Class



